﻿using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Windows;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using System.Threading.Tasks;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
using System.ComponentModel;
using PrsmMvvm.Models;

namespace PrsmMvvm.ViewModels
{
    public class TestWinViewModel : BindableBase
    {

        #region 属性
        private SeriesCollection _SeriesPieInfos;
        /// <summary>
        /// 饼图
        /// </summary>
        public SeriesCollection SeriesPieInfos
        {
            get { return _SeriesPieInfos; }
            set
            {
                if (_SeriesPieInfos != value)
                {
                    _SeriesPieInfos = value;
                    RaisePropertyChanged();
                }
            }
        }

        private SeriesCollection _SeriesCartesianInfos;
        /// <summary>
        /// 柱状图
        /// </summary>
        public SeriesCollection SeriesCartesianInfos
        {
            get { return _SeriesCartesianInfos; }
            set
            {
                if (_SeriesCartesianInfos != value)
                {
                    _SeriesCartesianInfos = value;
                    RaisePropertyChanged();
                }
            }
        }

        private List<string> _LabelXInfos;
        /// <summary>
        /// X坐标标签
        /// </summary>
        public List<string> LabelXInfos
        {
            get { return _LabelXInfos; }
            set
            {
                if (_LabelXInfos != value)
                {
                    _LabelXInfos = value;
                    RaisePropertyChanged();
                }
            }
        }

        private Func<double, string> _LabelYInfos;
        /// <summary>
        /// Y坐标表签
        /// </summary>
        public Func<double, string> LabelYInfos
        {
            get { return _LabelYInfos; }
            set
            {
                if (_LabelYInfos != value)
                {
                    _LabelYInfos = value;
                    RaisePropertyChanged();
                }
            }
        }
        #endregion

        #region 构造
        public TestWinViewModel()
        {
            Init();
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void Init()
        {
            SeriesPieInfos = new SeriesCollection
            {
                 new PieSeries
                 {
                     Title = "张三",
                     Values = new ChartValues<double> { 20 },
                     DataLabels = true
                 },
                 new PieSeries
                 {
                     Title = "李四",
                     Values = new ChartValues<double> { 60 },
                     DataLabels = true
                 },
                 new PieSeries
                 {
                     Title = "赵五",
                     Values = new ChartValues<double> { 30},
                     DataLabels = true
                 },
                 new PieSeries
                 {
                     Title = "王六",
                     Values = new ChartValues<double> { 50 },
                     DataLabels = true,
                 }
             };

            List<string> tempXInfos = new List<string>();
            List<double> y1Infos = new List<double>();
            List<double> y2Infos = new List<double>();
            for (int i = 0; i < 5; i++)
            {
                tempXInfos.Add($"{i + 1}月");

                y1Infos.Add(80 + i);
                y2Infos.Add(90 + i);
            }
            LabelXInfos = tempXInfos;

            List<string> tempYInfos = new List<string>();
            LabelYInfos = value => value + "分";

            SeriesCartesianInfos = new SeriesCollection
            {
                new ColumnSeries
                {
                    Title = "张三",
                    Values = new ChartValues<double>(y1Infos),
                    DataLabels = true,
                },
                new ColumnSeries
                {
                    Title = "李四",
                    Values = new ChartValues<double>(y2Infos),
                    DataLabels = true
                }
             };
        }
        #endregion
    }

}
